package com.kzd.gtgame.jetpack.manager

import com.kzd.gtgame.app.*
import com.kzd.gtgame.base.BaseManager
import com.kzd.gtgame.entity.*
import com.module.lemlin.http.HttpResponseData
import com.module.lemlin.http.HttpResponseDataE
import com.module.lemlin.http.HttpResponseDataT
import rxhttp.RxHttp
import rxhttp.await

class BargainRepository : BaseManager() {

    /**
     * 交易详情
     *
     * @param id 游戏id
     * */
    suspend fun bargainDetails(id: String): HttpResponseDataT<BargainDetails> =
        RxHttp.postForm(NEW_APPS_TRADE_INFO)
            .add("id", id)
            .await()


    /**
     * 我玩過的遊戲
     * */
    suspend fun bargainGamePlayed(): HttpResponseDataE<GamePlayed> =
        RxHttp.postForm(PERSONAL_MY_YOUXI)
            .await()

    /**
     * 小号选择
     * */
    suspend fun bargainGameSmall(
        gameId: String, appid: String
    ): HttpResponseDataE<GameSmall> = RxHttp.postForm(PERSONAL_GAME_SMALL_INFO)
        .add("game_id", gameId)
        .add("appid", appid)
        .await()

    suspend fun bargainSubmit(
        time: String,
        sign: String,
        name: String,
        game_id: String,
        introduction: String,
        sname: String,
        small_id: String,
        two_passwd: String? = null,
        money: String,
        system: String,
        images: String
    ): HttpResponseData = RxHttp.postForm(PERSONAL_TRADE_ADD)
        .add("t", time)
        .add("sign", sign)
        .add("name", name)
        .add("game_id", game_id)
        .add("introduction", introduction)
        .add("sname", sname)
        .add("small_id", small_id)
        .add("two_passwd", two_passwd)
        .add("money", money)
        .add("system", system)
        .add("images", images)
        .await()

    /**
     * 交易记录
     * */
    suspend fun bargainRecord(
        sign: String, time: String, page: String, type: String
    ): HttpResponseDataE<BargainRecord> = RxHttp.postForm(APP_TRADE_MY)
        .add("sign", sign)
        .add("t", time)
        .add("p", page)
        .add("type", type)
        .await()

    /**
     * 交易支付
     * */
    suspend fun bargainPayment(
        sign: String, time: String, type: String, goodsId: String, money: String
    ): BargainPaymentResponse = RxHttp.postForm(APP_TRADE_BUY)
        .add("sign", sign)
        .add("t", time)
        .add("type", type)
        .add("goods_id", goodsId)
        .add("money", money)
        .await()
}